package cn.e3mall.controller;

import cn.e3mall.common.util.E3Result;
import cn.e3mall.common.util.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.e3mall.pojo.TbItem;
import cn.e3mall.service.ItemService;

import java.util.HashMap;
import java.util.Map;

/**
 * 商品管理Controller
 * <p>Title: ItemController</p>
 * <p>Description: </p>
 * <p>Company: www.itcast.cn</p> 
 * @version 1.0
 */
@Controller
public class ItemController {

	@Autowired
	private ItemService itemService;
	
	@RequestMapping("/item/{itemId}")
	@ResponseBody
	public TbItem getItemById(@PathVariable Long itemId) {

		TbItem tbItem = itemService.getItemById(itemId);

		return tbItem;
	}
	@RequestMapping("/item/save")
	@ResponseBody
	public E3Result saveItem(TbItem item,String desc)
	{
		E3Result result = itemService.addItem(item,desc);
		return result;
	}
	@RequestMapping("/rest/item/delete")
	@ResponseBody
	public String delItem(Long ids){
		TbItem tbItem = itemService.delItem(ids);
		Map result = new HashMap<>();
		if(tbItem == null)
			result.put("status",-1);
		else
			result.put("status",200);
		String json = JsonUtils.objectToJson(result);
		return json;
	}
}
